<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
use app\models\Users;
class DemoController extends Controller
{
    public function actionAdd()
    {
        return $this->render("index");
    }

    public function actionIndex_do()
    {
        $data = Yii::$app->request->post();
        if($data['name']=='')
        {
            echo "用户名不能为空";
            die;
        }
        if($data['pwd']=='')
        {
            echo "密码不能为空";
            die;
        }
        $model = new Users();
        $model->tel=$data['tel'];
        $model->name=$data['name'];
        $model->pwd=$data['pwd'];
        $model->email=$data['email'];
        if(!$model->validate())
        {
            echo "验证有问题请重新验证";
            die;
        }

        $res = $model->add($data);

        if($res)
        {
            echo "添加成功";
        }else{
            echo "添加失败";
        }
    }
}





?>